using B.S.Data.MES.API.Applications.CangKu.Command;
using B.S.Domain.CangKu;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.S.Data.MES.API.Applications.CangKu.CommandHandlers
{
    public class DeleteCangKuCommandHandler : IRequestHandler<DeleteCangKuCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<CangKuinfo> _cangKuRepository;

        public DeleteCangKuCommandHandler(IBaseRepository<CangKuinfo> cangKuRepository)
        {
            _cangKuRepository = cangKuRepository;
        }

        public async Task<APIRequst<int>> Handle(DeleteCangKuCommand request, CancellationToken cancellationToken)
        {
            // 软删除：更新isDel字段为1
            var cangKu =  _cangKuRepository.GetAll().FirstOrDefault(x=>x.CangId==request.CangId);
            cangKu.isDel = true;
            await _cangKuRepository.Update(cangKu);
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            };
        }
    }
}